# coding=utf8
# 全世界最帅的帅哥
from flask_restful import Resource, reqparse
from comment.modules.funding_not_matched import FundingNotMatched
from .serializer import AllMatchedPaginateSerializer
from comment.utils.decorators import root_login_required


class AllMatchedResource(Resource):
    method_decorators = [root_login_required]

    # 所有资金列表  待匹配和已经匹配完全的资金列表
    def get(self):
        rp = reqparse.RequestParser()
        rp.add_argument("curPage")  # 当前页
        rp.add_argument("perPage")  # 每页的数量
        rp.add_argument("type")  # 匹配状态  传入2查看所有已经匹配的  未匹配的不用传

        args = rp.parse_args()

        cur_page = int(args.curPage)
        per_page = int(args.perPage)
        status = int(args.type) if args.type == "2" else None

        if not status:
            # 查询所有未匹配和部分匹配的
            match_list = FundingNotMatched.query.filter(FundingNotMatched.matchedStatus != 2)
        else:
            match_list = FundingNotMatched.query.filter(FundingNotMatched.matchedStatus == 2)

        match_list = match_list.paginate(page=cur_page, per_page=per_page, error_out=False)
        match_data = AllMatchedPaginateSerializer(match_list).to_dict()
        return {"msg": "查看资金列表成功", "data": match_data}
